//
//  HZJTabBarController.swift
//  HZJTab
//
//  Created by HZJ on 2017/4/7.
//  Copyright © 2017年 HZJ. All rights reserved.
//

import UIKit

class HZJTabBarController: UITabBarController,HZJTabbarDelegate {

    var myTab:HZJTabbar = HZJTabbar()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        addChildVCsWithTab()
    }
    
    func addChildVCsWithTab() {
        let storyBoard = UIStoryboard(name: "Main", bundle: nil)
        let n1 = storyBoard.instantiateViewController(withIdentifier: "1")
        let n2 = storyBoard.instantiateViewController(withIdentifier: "2")
        let n3 = storyBoard.instantiateViewController(withIdentifier: "3")
        let vcs = [n1,n2,n3]
        self.viewControllers = vcs
//        let titleArr = [Localized("one"),Localized("two"),Localized("three")]
        let titleArr = ["one","two","three"]

        let imgStrArr = ["1","1","2","3"]
        let selectedImgStrArr = ["3","3","3"]
        myTab.tabBarWith(vcs.count, titleArray: titleArr, imgStrs: imgStrArr, selectedImageStrs: selectedImgStrArr)
        myTab.frame = self.tabBar.bounds
        myTab.insertNoSelectedBtn("tiao", btnImageName: nil, btnIndex: -1, atIndex: 1,isNormalBtn:true)
        myTab.btnArray[0].badgeValue = "12"
        myTab.btnArray[2].badgeValue = ""
        myTab.delegate = self
        
        
        for v in self.tabBar.subviews {
            v.removeFromSuperview()
        }
        self.tabBar.addSubview(myTab)
        
        self.selectedIndex = 2
        self.myTab.selectedIndex = 2
        
    }
    func clickTheTarBarButton(_ btn: HZJTabBarButton) {
        if btn.index >= 0 {
            self.selectedIndex = btn.index
        }else{
            self.present(ViewController(), animated: true, completion: nil)
        }
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

}
